package com.guotd.jspwork2.controller;

import com.guotd.jspwork2.utils.JDBCUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/selectKind")
public class selectKindServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int kindId = Integer.parseInt(request.getParameter("kindId"));
        String sql = "select * from kind where id=?";
        String[] args = {String.valueOf(kindId)};
        String []colNames ={"id","kind","desc"};
        List<Object[]> oneKind = JDBCUtil.query(sql, args, colNames);
        request.getSession().setAttribute("oneKind", oneKind);
        request.getSession().setAttribute("kindId", kindId);
        System.out.println(oneKind);
        response.sendRedirect("edit_kind.jsp");
    }
}

